# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p2.py
# @Time     : 2024/5/7 22:46
# @Author   : Robot-Zsj
"""
description:


跳房子I

https://fcqian.blog.csdn.net/article/details/130766192?spm=1001.2014.3001.5502

i:
[1,4,5,2,2]
7

o:
[5,2]

"""
import sys

steps = list(map(int, input()[1:-1].split(',')))
count = int(input())


def getResult():
    dic = {}

    minIdSum = sys.maxsize
    ans = ""

    for idx1 in range(len(steps)):
        step1 = steps[idx1]
        step2 = count - step1
        if dic.get(step2) is None:
            dic.setdefault(step1, idx1)
        else:
            idx2 = dic[step2]
            idxSum = idx1 + idx2
            if idxSum < minIdSum:
                minIdSum = idxSum
                ans = f"[{step2}, {step1}]"
    return ans


print(getResult())
